home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / Chip_2004-07_cd1.bin / oddech / pipe / PipeDownDemo.exe / 2057 / SHOCKWAVE / 132 / 00005_3D Behaviour.ls < prev    next >
Encoding:
Text File  |  2004-05-25  |  18.1 KB  |  673 lines

  1. property pStraights, pBends, pBoxes, pBoxesPos, pStraightsReset, pBendsReset, pStraightsComplete, pBendsComplete, hk, pBall, pBallRB, pPipes, pArrow, pCup, pGap, pNormalShader, pGlowShader, pNoHks, pTime, pTimeGone, pPipeActive, pPipeTotal, pPipesUsed, pAdjSlots, pLandCount, pStuckCount, pFadeState, pLevelScore, pPipeScore, pMovesLeft, pMovesMax, pLevelFailure, leftkey, rightkey, downkey, upkey, spacekey, dcam, cam, dcamCenter, pCamZoom, pCamRotate, pRotX, pRotY, pMousePrevX, pMousePrevY, pRotations, pSucker, pLoaderData
  2. global w3d, gKeyOn, gGameMode, gLevel, gScore, gSkillMode, gMenuCalled, gGameType, gPuzzleSize, gClickedArrow
  3.  
  4. on beginSprite me
  5.   w3d = sprite(2).member
  6.   w3d.resetWorld()
  7.   hk = member(1)
  8.   hk.Initialize(w3d, 1, 0.025)
  9.   pStraights = []
  10.   pBends = []
  11.   pBoxes = []
  12.   pBoxesPos = []
  13.   pRotations = [vector(0, 0, 90), vector(90, 0, 0), vector(0, 0, 0), vector(0, 90, 0), vector(0, 180, 0), vector(0, 270, 0), vector(180, 0, 0), vector(180, 90, 0), vector(0, 0, 180), vector(180, 270, 0), vector(0, 270, 90), vector(90, 0, 0), vector(270, 0, 0), vector(0, 90, 90)]
  14.   loadLevel()
  15.   getCompleteLevels()
  16.   setupGame()
  17.   setupObjects(me)
  18.   setupCamera()
  19. end
  20.  
  21. on loadLevel
  22.   if gGameType = "full" then
  23.     levelMember = member("Levels")
  24.   else
  25.     levelMember = member("LevelsDemo")
  26.   end if
  27.   txt = levelMember.text.line[gLevel]
  28.   if txt.word.count < 8 then
  29.     alert("Error loading level")
  30.     return 
  31.   end if
  32.   pLoaderData = []
  33.   pLoaderData.add(vector(float(txt.word[4]), float(txt.word[5]), float(txt.word[6])))
  34.   pLoaderData.add(vector(float(txt.word[7]), float(txt.word[8]), float(txt.word[9])))
  35.   pLoaderData.add(integer(txt.word[3]))
  36.   n = 10
  37.   lim = value(txt.word[2])
  38.   gPuzzleSize = lim
  39.   m = w3d.model[1]
  40.   t = m.getWorldTransform()
  41.   repeat with x = 1 to lim
  42.     repeat with y = 1 to lim
  43.       repeat with z = 1 to lim
  44.         i = integer(txt.word[n])
  45.         n = n + 1
  46.         if (i > 0) and (i < 4) then
  47.           m.transform = transform()
  48.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  49.           if i <> 1 then
  50.             m.rotate(pRotations[i - 1])
  51.           end if
  52.           pStraights.add(m.transform.duplicate())
  53.           next repeat
  54.         end if
  55.         if (i > 3) and (i < 16) then
  56.           m.transform = transform()
  57.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  58.           m.rotate(pRotations[i - 1])
  59.           pBends.add(m.transform.duplicate())
  60.           next repeat
  61.         end if
  62.         if i = 16 then
  63.           pBoxesPos.add(vector((x - 1) * 16, (y - 1) * -16, (z - 1) * -16))
  64.         end if
  65.       end repeat
  66.     end repeat
  67.   end repeat
  68.   m.transform = t
  69. end
  70.  
  71. on getCompleteLevels
  72.   if gGameType = "full" then
  73.     levelMember = member("LevelsComplete")
  74.   else
  75.     levelMember = member("LevelsCompleteDemo")
  76.   end if
  77.   txt = levelMember.text.line[gLevel]
  78.   if txt.word.count < 8 then
  79.     alert("Error loading complete level")
  80.     return 
  81.   end if
  82.   pStraightsComplete = []
  83.   pBendsComplete = []
  84.   n = 10
  85.   m = w3d.model[1]
  86.   t = m.getWorldTransform()
  87.   repeat with x = 1 to gPuzzleSize
  88.     repeat with y = 1 to gPuzzleSize
  89.       repeat with z = 1 to gPuzzleSize
  90.         i = integer(txt.word[n])
  91.         n = n + 1
  92.         if (i > 0) and (i < 4) then
  93.           m.transform = transform()
  94.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  95.           if i <> 1 then
  96.             m.rotate(pRotations[i - 1])
  97.           end if
  98.           pStraightsComplete.add(m.transform.duplicate())
  99.           next repeat
  100.         end if
  101.         if (i > 3) and (i < 16) then
  102.           m.transform = transform()
  103.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  104.           m.rotate(pRotations[i - 1])
  105.           pBendsComplete.add(m.transform.duplicate())
  106.         end if
  107.       end repeat
  108.     end repeat
  109.   end repeat
  110.   m.transform = t
  111. end
  112.  
  113. on setupObjects me
  114.   pGlowShader = w3d.shader("GlowGlassShader")
  115.   pNormalShader = w3d.shader("GlassShader")
  116.   pNormalShader.blend = 50
  117.   pGlowShader.blend = 70
  118.   hk.gravity = vector(0, -200, 0)
  119.   pBall = w3d.model("Ball")
  120.   pCup = w3d.model("Cup")
  121.   pSucker = w3d.model("BallSucker")
  122.   pBall.worldPosition = pLoaderData[1]
  123.   pCup.worldPosition = pLoaderData[2]
  124.   pSucker.transform.position = pBall.worldPosition
  125.   if gPuzzleSize > 3 then
  126.     w3d.model("BoxOutline").scale(1.33329999999999993, 1.33329999999999993, 1.33329999999999993)
  127.   end if
  128.   pPipes = []
  129.   num = 1
  130.   repeat with i = 1 to pStraights.count
  131.     w3d.model("Pipe_Straight(Glass)").clone("Pipe" & num)
  132.     m = w3d.model("Pipe" & num)
  133.     m.transform = pStraights[i]
  134.     pPipes.add(m)
  135.     num = num + 1
  136.   end repeat
  137.   repeat with i = 1 to pBends.count
  138.     w3d.model("Pipe_Bend(Glass)").clone("Pipe" & num)
  139.     m = w3d.model("Pipe" & num)
  140.     m.transform = pBends[i]
  141.     pPipes.add(m)
  142.     num = num + 1
  143.   end repeat
  144.   pPipeTotal = num - 1
  145.   w3d.deleteModel("Pipe_Straight(Glass)")
  146.   w3d.deleteModel("Pipe_Bend(Glass)")
  147.   w3d.deleteModel("Glow_Bend(Glass)")
  148.   w3d.deleteModel("Glow_Straight(Glass)")
  149.   pPipeActive = pPipes[1]
  150.   pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
  151.   pBoxes = []
  152.   repeat with i = 1 to pBoxesPos.count
  153.     w3d.model("BoxChrome").clone("BoxChrome" & i)
  154.     m = w3d.model("BoxChrome" & i)
  155.     m.transform.position = pBoxesPos[i]
  156.     pBoxes.add(m)
  157.   end repeat
  158.   w3d.deleteModel("BoxChrome")
  159.   pArrow = [w3d.model("Arrow")]
  160.   pArrow[1].scale(1.5)
  161.   pArrow[1].pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
  162.   repeat with i = 1 to 5
  163.     b = w3d.model("Arrow").clone("Arrow" & i)
  164.     b.pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
  165.     pArrow.add(b)
  166.   end repeat
  167.   setArrows()
  168.   bf = w3d.newTexture("BlackFade", #fromCastMember, member("black"))
  169.   w3d.camera[1].addOverlay(bf, point(0, 0), 0)
  170.   w3d.camera[1].overlay[1].scale = 840
  171.   w3d.camera[1].overlay[1].blend = 100
  172.   if not gClickedArrow then
  173.     bf = w3d.newTexture("helpOL", #fromCastMember, member("helpOL"))
  174.     w3d.camera[1].addOverlay(bf, point(80, 570), 0)
  175.     w3d.camera[1].overlay[2].blend = 0
  176.   end if
  177. end
  178.  
  179. on setPipes setType
  180.   if setType = "start" then
  181.     straights = pStraights
  182.     bends = pBends
  183.   else
  184.     if setType = "complete" then
  185.       straights = pStraightsComplete
  186.       bends = pBendsComplete
  187.     else
  188.       if setType = "back" then
  189.         straights = pStraightsReset
  190.         bends = pBendsReset
  191.       end if
  192.     end if
  193.   end if
  194.   pStraightsReset = []
  195.   pBendsReset = []
  196.   num = 1
  197.   repeat with i = 1 to pStraights.count
  198.     m = w3d.model("Pipe" & num)
  199.     pStraightsReset[i] = m.getWorldTransform()
  200.     m.transform = straights[i]
  201.     num = num + 1
  202.   end repeat
  203.   repeat with i = 1 to pBends.count
  204.     m = w3d.model("Pipe" & num)
  205.     pBendsReset[i] = m.getWorldTransform()
  206.     m.transform = bends[i]
  207.     num = num + 1
  208.   end repeat
  209.   setArrows()
  210. end
  211.  
  212. on getShaderNum pipe
  213.   if string(pipe.resource.name).length < 20 then
  214.     return 2
  215.   else
  216.     return 1
  217.   end if
  218. end
  219.  
  220. on makeHK
  221.   pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
  222.   repeat with i = 1 to 6
  223.     pArrow[i].transform.position = vector(0, 1000, 0)
  224.   end repeat
  225.   pNoHks = ["Ball", "Marker"]
  226.   pBall.addModifier(#meshDeform)
  227.   pBallRB = hk.makeMovableRigidBody(pBall.name, 1, 1, #sphere)
  228.   pBallRB.restitution = 0.20000000000000001
  229.   pBallRB.friction = 0.80000000000000004
  230.   pBallRB.linearVelocity = vector(0, 0, 0)
  231.   pBallRB.angularVelocity = vector(0, 0, 0)
  232.   pCup.addModifier(#meshDeform)
  233.   rb = hk.makeFixedRigidBody(pCup.name, 0)
  234.   rb.restitution = 0.0
  235.   rb.friction = 0.80000000000000004
  236.   repeat with i = 1 to pPipes.count
  237.     pPipes[i].addModifier(#meshDeform)
  238.     rb = hk.makeFixedRigidBody(pPipes[i].name, 0)
  239.     rb.restitution = 0.0
  240.     rb.friction = 0.80000000000000004
  241.   end repeat
  242.   pGap = []
  243.   m = w3d.model[1]
  244.   t = m.getWorldTransform()
  245.   repeat with x = 1 to gPuzzleSize
  246.     repeat with y = 1 to gPuzzleSize
  247.       repeat with z = 1 to gPuzzleSize
  248.         m.transform = transform()
  249.         m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  250.         foundPipe = 0
  251.         repeat with p in pPipes
  252.           dPipe = m.worldPosition.distanceTo(p.worldPosition)
  253.           if dPipe < 5 then
  254.             foundPipe = 1
  255.           end if
  256.         end repeat
  257.         if not foundPipe then
  258.           pGap.add(m.worldPosition)
  259.         end if
  260.       end repeat
  261.     end repeat
  262.   end repeat
  263.   m.transform = t
  264.   soundFX("drop", 3, 255)
  265.   mend = member("roll").duration
  266.   sound(2).volume = 0
  267.   sound(2).play([#member: member("roll"), #startTime: 0, #endTime: mend, #loopStartTime: 0, #loopEndTime: mend, #loopCount: 1000])
  268.   gGameMode = #drop
  269. end
  270.  
  271. on setupGame
  272.   pTime = the timer
  273.   pAdjSlots = [vector(16, 0, 0), vector(-16, 0, 0), vector(0, 16, 0), vector(0, -16, 0), vector(0, 0, 16), vector(0, 0, -16)]
  274.   pLandCount = 0
  275.   pStuckCount = 0
  276.   pLevelScore = 0
  277.   pPipeScore = 0
  278.   pMovesMax = pLoaderData[3]
  279.   if gSkillMode < 3 then
  280.     pMovesLeft = pMovesMax * 2
  281.   else
  282.     pMovesLeft = pMovesMax
  283.   end if
  284.   pPipesUsed = 0
  285.   pFadeState = #up
  286.   pLevelFailure = 0
  287.   setVariable(sprite(1), "score", string(gScore))
  288.   setVariable(sprite(1), "level", string(gLevel))
  289.   setVariable(sprite(1), "movesLeft", string(pMovesLeft))
  290.   moveFlash("main" & gSkillMode)
  291.   gMenuCalled = 0
  292.   gGameMode = #play
  293. end
  294.  
  295. on checkTimer
  296.   pTimeGone = the timer - pTime
  297.   if (pTimeGone > 200) and not gClickedArrow then
  298.     if w3d.camera[1].overlay[2].blend = 0 then
  299.       w3d.camera[1].overlay[2].blend = 100
  300.     end if
  301.   end if
  302.   ntSecs = integer(pTimeGone / 60.0)
  303.   ntMins = integer(ntSecs / 60.0)
  304.   ntSecs = integer(ntSecs - (ntMins * 60.0))
  305.   if ntSecs < 0 then
  306.     ntMins = ntMins - 1
  307.     ntSecs = ntSecs + 60
  308.   end if
  309.   if ntMins < 10.0 then
  310.     ntMins = "0" & string(ntMins)
  311.   end if
  312.   if ntSecs < 10.0 then
  313.     ntSecs = "0" & string(ntSecs)
  314.   end if
  315.   nt = string(ntMins) & ":" & string(ntSecs)
  316.   setVariable(sprite(1), "time", nt)
  317. end
  318.  
  319. on enterFrame
  320.   prevScore = pLevelScore
  321.   if gGameMode = #dropbutton then
  322.     makeHK()
  323.     gGameMode = #drop
  324.   else
  325.     if gGameMode = #drop then
  326.       checkDrop()
  327.     else
  328.       if gGameMode = #play then
  329.         checkTimer()
  330.       else
  331.         if gGameMode = #reset then
  332.           setPipes("start")
  333.           gGameMode = #play
  334.         else
  335.           if gGameMode = #hint then
  336.             setPipes("complete")
  337.             gGameMode = #hintwait
  338.           else
  339.             if gGameMode = #hintwait then
  340.               checkTimer()
  341.             else
  342.               if gGameMode = #hintend then
  343.                 setPipes("back")
  344.                 gGameMode = #play
  345.               else
  346.                 if gGameMode = #finish then
  347.                   if pFadeState <> #down then
  348.                     pFadeState = #down
  349.                   end if
  350.                 end if
  351.               end if
  352.             end if
  353.           end if
  354.         end if
  355.       end if
  356.     end if
  357.   end if
  358.   updateCamera()
  359.   if pLevelScore <> prevScore then
  360.     setVariable(sprite(1), "levelScore", string(pLevelScore))
  361.   end if
  362.   if pFadeState <> #none then
  363.     fadeLevel()
  364.   end if
  365. end
  366.  
  367. on checkDrop
  368.   pos = pBall.worldPosition
  369.   vel = pBallRB.linearVelocity.magnitude
  370.   sound(2).volume = vel
  371.   if vel < 5 then
  372.     pStuckCount = pStuckCount + 1
  373.   else
  374.     pStuckCount = 0
  375.   end if
  376.   repeat with p in pPipes
  377.     dPipe = pos.distanceTo(p.worldPosition)
  378.     ps = p.shaderList[getShaderNum(p)].name
  379.     if (dPipe < 10) and (ps = "GlassShader") then
  380.       soundFX("light", 3, 100)
  381.       pPipesUsed = pPipesUsed + 1
  382.       p.shaderList[getShaderNum(p)] = pGlowShader
  383.     end if
  384.   end repeat
  385.   if gSkillMode > 1 then
  386.     repeat with p in pGap
  387.       dGap = pos.distanceTo(p)
  388.       if dGap < 10 then
  389.         pLevelFailure = 1
  390.       end if
  391.     end repeat
  392.   end if
  393.   dCup = pos.distanceTo(pCup.worldPosition)
  394.   if dCup < 12 then
  395.     pLandCount = pLandCount + 1
  396.   end if
  397.   if (pLandCount > 0) and (pLandCount < 50) then
  398.     dy = pos.y - pCup.worldPosition.y
  399.     if dy < 0 then
  400.       soundFX("land", 3, 100)
  401.       sound(2).stop()
  402.       pLandCount = 50
  403.     end if
  404.   end if
  405.   if pLandCount > 70 then
  406.     gGameMode = #finish
  407.   end if
  408.   dy = pCup.worldPosition.y - pos.y
  409.   if dy > 0 then
  410.     sound(2).volume = 0
  411.   end if
  412.   if (dy > 500) or (pStuckCount > 100) then
  413.     pLevelFailure = 1
  414.     gGameMode = #finish
  415.   end if
  416. end
  417.  
  418. on setArrows
  419.   repeat with i = 1 to 6
  420.     pArrow[i].transform.position = vector(0, 1000, 0)
  421.   end repeat
  422.   arrowNum = 1
  423.   p = pPipeActive.worldPosition
  424.   if gPuzzleSize = 3 then
  425.     upperLimit = 33
  426.   else
  427.     if gPuzzleSize = 4 then
  428.       upperLimit = 49
  429.     end if
  430.   end if
  431.   repeat with i in pAdjSlots
  432.     pos = p + i
  433.     if (pos.x < upperLimit) and (pos.x > -1) and (pos.y < 1) and (pos.y > -upperLimit) and (pos.z < 1) and (pos.z > -upperLimit) then
  434.       blocked = 0
  435.       repeat with b in pPipes
  436.         d = (pos - b.worldPosition).magnitude
  437.         if d < 1 then
  438.           blocked = 1
  439.         end if
  440.       end repeat
  441.       repeat with b in pBoxes
  442.         d = (pos - b.worldPosition).magnitude
  443.         if d < 1 then
  444.           blocked = 1
  445.         end if
  446.       end repeat
  447.       if not blocked then
  448.         pArrow[arrowNum].transform.position = pos
  449.         pArrow[arrowNum].translate(0.01, 0.01, 0.01)
  450.         pArrow[arrowNum].pointAt(p + (i * 2), vector(0, 1, 0))
  451.         pArrow[arrowNum].transform.position = pos
  452.         arrowNum = arrowNum + 1
  453.       end if
  454.     end if
  455.   end repeat
  456. end
  457.  
  458. on fadeLevel
  459.   f = cam.overlay[1].blend
  460.   if pFadeState = #up then
  461.     if f > 0 then
  462.       cam.overlay[1].blend = f - 5
  463.     else
  464.       cam.overlay[1].blend = 0
  465.       pFadeState = #none
  466.     end if
  467.   else
  468.     if pFadeState = #down then
  469.       if f < 100 then
  470.         cam.overlay[1].blend = f + 5
  471.       else
  472.         cam.overlay[1].blend = 100
  473.         pFadeState = #none
  474.         endOfLevel()
  475.       end if
  476.     end if
  477.   end if
  478. end
  479.  
  480. on endOfLevel
  481.   pipesScore = integer(pPipesUsed / float(pPipeTotal) * 100)
  482.   if (gSkillMode = 3) or (pMovesLeft >= pMovesMax) then
  483.     movesScore = 100
  484.   else
  485.     movesScore = integer(pMovesLeft / float(pMovesMax) * 100)
  486.   end if
  487.   maxSecs = pMovesMax * 6
  488.   secs = integer(pTimeGone / 60.0)
  489.   if secs < maxSecs then
  490.     timeScore = 100
  491.   else
  492.     timeScore = integer(((maxSecs * 2) - secs) / float(maxSecs) * 100)
  493.   end if
  494.   if timeScore < 0 then
  495.     timeScore = 0
  496.   end if
  497.   if gMenuCalled or ((gSkillMode > 1) and (pipesScore < 100)) then
  498.     pLevelFailure = 1
  499.   end if
  500.   if pLevelFailure then
  501.     if not gMenuCalled then
  502.       gLevel = gLevel - 1
  503.     end if
  504.     pipesScore = 0
  505.     movesScore = 0
  506.     timeScore = 0
  507.     levelScore = 0
  508.     setVariable(sprite(1), "levelButtTxt", "REPLAY LEVEL")
  509.   else
  510.     setVariable(sprite(1), "levelButtTxt", "NEXT LEVEL")
  511.     levelScore = integer((pipesScore + movesScore + timeScore) / 3.0)
  512.   end if
  513.   gScore = gScore + levelScore
  514.   setVariable(sprite(1), "movesScore", string(movesScore))
  515.   setVariable(sprite(1), "timeScore", string(timeScore))
  516.   setVariable(sprite(1), "pipeScore", string(pipesScore))
  517.   setVariable(sprite(1), "levelScore", string(levelScore))
  518.   setVariable(sprite(1), "score", string(gScore))
  519.   repeat with i = 1 to 8
  520.     sound(i).stop()
  521.   end repeat
  522.   go(the frame + 1)
  523. end
  524.  
  525. on setupCamera
  526.   cam = w3d.camera[1]
  527.   cam.fieldOfView = 50
  528.   dcam = w3d.newModel("dummyCam")
  529.   dcamCenter = w3d.newModel("dummyCenter")
  530.   if gPuzzleSize = 3 then
  531.     dcamCenter.transform.position = vector(16, -16, -16)
  532.     pCamZoom = 60
  533.   else
  534.     if gPuzzleSize = 4 then
  535.       dcamCenter.transform.position = vector(24, -24, -24)
  536.       pCamZoom = 80
  537.     end if
  538.   end if
  539.   dcamCenter.addChild(dcam, #preserveParent)
  540.   dcam.translate(-pCamZoom, 0, -pCamZoom)
  541.   pRotX = 0
  542.   pRotY = 0
  543. end
  544.  
  545. on mouseDown me
  546.   clickItem = 0
  547.   if gGameMode = #play then
  548.     m = cam.modelsUnderLoc(the mouseLoc, 3, #simple)
  549.     if m.count > 0 then
  550.       repeat with i = 1 to m.count
  551.         if chars(m[i].name, 1, 5) = "Arrow" then
  552.           pPipeActive.worldPosition = m[i].worldPosition
  553.           pMovesLeft = pMovesLeft - 1
  554.           if pMovesLeft < 0 then
  555.             pMovesLeft = 0
  556.           end if
  557.           if gSkillMode > 1 then
  558.             if pMovesLeft = 0 then
  559.               gGameMode = #dropbutton
  560.             end if
  561.             setVariable(sprite(1), "movesLeft", string(pMovesLeft))
  562.           end if
  563.           setArrows()
  564.           soundFX("click", 3, 50)
  565.           clickItem = 1
  566.           if not gClickedArrow then
  567.             if w3d.camera[1].overlay[2].blend > 0 then
  568.               w3d.camera[1].overlay[2].blend = 0
  569.             end if
  570.             gClickedArrow = 1
  571.           end if
  572.           exit repeat
  573.           next repeat
  574.         end if
  575.         if chars(m[i].name, 1, 4) = "Pipe" then
  576.           pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
  577.           pPipeActive = m[i]
  578.           pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
  579.           setArrows()
  580.           clickItem = 1
  581.           soundFX("choose", 3, 100)
  582.           exit repeat
  583.         end if
  584.       end repeat
  585.     end if
  586.   end if
  587.   if not clickItem then
  588.     pCamRotate = 1
  589.     pMousePrevX = (the mouseLoc).locH
  590.     pMousePrevY = (the mouseLoc).locV
  591.   end if
  592. end
  593.  
  594. on mouseWithin me
  595.   if pCamRotate then
  596.     pRotX = (the mouseLoc).locH - pMousePrevX
  597.     pRotY = (the mouseLoc).locV - pMousePrevY
  598.     pMousePrevX = (the mouseLoc).locH
  599.     pMousePrevY = (the mouseLoc).locV
  600.   end if
  601.   if pRotX > 10 then
  602.     pRotX = 10
  603.   else
  604.     if pRotX < -10 then
  605.       pRotX = -10
  606.     end if
  607.   end if
  608.   if pRotY > 10 then
  609.     pRotY = 10
  610.   else
  611.     if pRotY < -10 then
  612.       pRotY = -10
  613.     end if
  614.   end if
  615. end
  616.  
  617. on mouseLeave me
  618.   mouseUp(me)
  619. end
  620.  
  621. on mouseUp me
  622.   pCamRotate = 0
  623. end
  624.  
  625. on updateCamera
  626.   checkkeys()
  627.   dcam.transform.position.z = pCamZoom
  628.   dcam.transform.position.x = pCamZoom
  629.   if upkey then
  630.   else
  631.     if downkey then
  632.     end if
  633.   end if
  634.   if pCamRotate then
  635.     dcamCenter.rotate(0, -pRotX, 0)
  636.     dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), -pRotY * 2, #self)
  637.   end if
  638.   if abs(dcam.worldPosition.y + 16) > 85 then
  639.     dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), pRotY * 2.20000000000000018, #self)
  640.   end if
  641.   dcam.pointAt(dcamCenter.worldPosition, vector(0, 1, 0))
  642.   camBuffer = 20
  643.   cam.transform.interpolateTo(dcam.getWorldTransform(), camBuffer)
  644. end
  645.  
  646. on checkkeys
  647.   leftkey = 0
  648.   rightkey = 0
  649.   downkey = 0
  650.   upkey = 0
  651.   spacekey = 0
  652.   if keyPressed(123) then
  653.     leftkey = 1
  654.   end if
  655.   if keyPressed(124) then
  656.     rightkey = 1
  657.   end if
  658.   if keyPressed(125) then
  659.     downkey = 1
  660.   end if
  661.   if keyPressed(126) then
  662.     upkey = 1
  663.   end if
  664.   if keyPressed(" ") then
  665.     spacekey = 1
  666.   end if
  667. end
  668.  
  669. on endSprite me
  670.   hk.shutDown()
  671.   w3d.resetWorld()
  672. end
  673.